package logic

import (
	"context"
	"shuqi_novel/shop_rpc/shoprpcclient"

	"shuqi_novel/api/internal/svc"
	"shuqi_novel/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookAddLogic {
	return &BookAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookAddLogic) BookAdd(req *types.BookAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.ShopRpc.BookAdd(l.ctx, &shoprpcclient.BookAddRequest{
		AuthorId: int64(req.AuthorId),
		Title:    req.Title,
		Type:     req.Type,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "小说创建成功",
		Data:    add,
	}, nil
}
